/*******************************************
Module: zt_thread.h
E-Mail: 24zhutian@gmail.com
Notices: Copyright (c) 2007-2011 ls
*******************************************/
#ifndef zt_thread_h
#define zt_thread_h

#ifdef __cplusplus
extern "C" {
#endif

#ifndef u_long
typedef unsigned long u_long;
#endif
	
typedef unsigned (__stdcall *ZT_PTHREAD_START)(void *);
typedef enum zt_thread_status_e{
	ZT_THREAD_RUN=0,
	ZT_THREAD_PAUSE,
	ZT_THREAD_STOP
}zt_thread_status_t;

typedef struct zt_thread_s{
	void *object;
	unsigned id;
	
	void *security;
	unsigned stack_size;
	unsigned initflag;
	
	ZT_PTHREAD_START lpfn;
	void *args;
	
	int priority;
	u_long timeout;
	
	int status;
	int abort;
}zt_thread_t;

#define zt_thread_abort(pt)		((pt)->abort=1)
#define zt_thread_is_abort(pt)	((pt)->abort==1)

#define	zt_thread_id			GetCurrentThreadId()

ZT_API int		zt_thread_init(zt_thread_t *pt);

ZT_API u_long	zt_thread_start(zt_thread_t *pt,ZT_PTHREAD_START lpfn,void *args);
ZT_API u_long	zt_thread_suspend(zt_thread_t *pt);
ZT_API u_long	zt_thread_resume(zt_thread_t *pt);

ZT_API int		zt_thread_set_priority(zt_thread_t *pt);
ZT_API int		zt_thread_post_message(zt_thread_t *pt,UINT msg,WPARAM wParam,LPARAM lParam);

ZT_API u_long	zt_thread_waitpid(zt_thread_t *pt);
ZT_API int		zt_thread_close(zt_thread_t *pt);
ZT_API int		zt_thread_exit(zt_thread_t *pt);
	
#ifdef __cplusplus
}
#endif /* C++ */
#endif /* zt_thread_h */
